package com.neutech.neusys.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.neutech.neusys.mapper.DeptMapper;
import com.neutech.neusys.service.DeptService;
import com.neutech.po.Dept;
import com.neutech.vo.ViewData;

@Service
public class DeptServiceImpl implements DeptService{
	@Autowired
	private DeptMapper deptMapper;
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int addNewDept(Map<String, Object> dept) {
		// TODO Auto-generated method stub
		return deptMapper.addNewDept(dept);
	}
	@Override
	public ViewData getdept(Map<String,Object> map) {
		// TODO Auto-generated method stub
		
		//前端传递的pagaNumber页码数 转换为数字 并且减一 ,计算出limit起始数据值然后替换原有的map的值
		String pageNumber = (String)map.get("pageNumber");
		try{
			Integer pn = new Integer(pageNumber);
			pn = pn-1;
			if(pn<0){
				pn = 0;
			}
			pn = pn*10;
			map.put("pageNumber", pn);
		}catch(Exception e){
			map.put("pageNumber", 0);
		}
		System.out.println(pageNumber);
		System.out.println(map.get("DeptName"));
		ViewData vd = new ViewData();
		vd.setMap(deptMapper.getdept(map));//加入数据库查询的一页数据
		//以及加入数据库查询的总条目数
		vd.setPageNumber(deptMapper.getdeptCount(map));
		return vd;
	}
	@Override
	public int updateDept(Map<String, Object> dept) {
		// TODO Auto-generated method stub
		return deptMapper.updatedept(dept);
	}
	@Override
	public int deletdept(Dept dept) {
		// TODO Auto-generated method stub
		int num = deptMapper.deletdept(dept);
		return num;
	}

}
